package com.zone.customview;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.SweepGradient;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

/**
 * Created by zone on 2017/5/2.
 */

public class RadarSweepView extends View {
    private String TAG = "zoneLog";
    private float value;

    public RadarSweepView(Context context) {
        super(context);
    }

    public RadarSweepView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RadarSweepView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public RadarSweepView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onDraw(final Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(getResources().getColor(R.color.huaweiClockView));
        final Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.RED);
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        SweepGradient sweepGradient = new SweepGradient(0,0,new int[] {0X10000000,Color.WHITE},null);
        paint.setShader(sweepGradient);
        canvas.translate(getWidth()/2,getHeight()/2);
        final RectF rectF = new RectF(-300, -300, 300, 300);
        ValueAnimator animator = ValueAnimator.ofFloat(0, 180);
        animator.setDuration(5000);
//        animator.setRepeatCount(ValueAnimator.INFINITE);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                Log.d(TAG, "onAnimationUpdate: "+animation.getAnimatedValue());
                value ++;
                canvas.drawArc(rectF, value,180f, true, paint);
                postInvalidate();

            }
        });
        animator.start();


//canvas.drawArc(¥Y);

    }
}

